<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增酒店服务')" />
    <th:block th:include="include :: bootstrap-fileinput-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-service-add">
            <div class="form-group">    
                <label class="col-sm-3 control-label">服务项：</label>
                <div class="col-sm-8">
                    <input name="service" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">服务详情：</label>
                <div class="col-sm-8">
                    <textarea name="detail" class="form-control"></textarea>
                </div>
            </div>
            <input name="pic" id="pic" class="form-control" type="hidden" value="/index/images/about_ct_b.jpg">
            <div class="form-group">
                <label class="col-sm-3 control-label">服务图片上传：</label>
                <div class="fileinput fileinput-new col-sm-8" data-provides="fileinput">
                    <div class="fileinput-new thumbnail" style="width: 140px; height: 140px;">
                        <img src="/index/images/about_ct_b.jpg" id="uploadImg">
                    </div>
                    <div>
                        <span class="btn btn-white btn-file">
                            <span class="fileinput-new">选择图片</span>
                            <span class="fileinput-exists">更改</span>
                            <input type="file" name="filePath" id="filePath" onchange="uploadFile()" accept="image/*">
                        </span>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <script type="text/javascript">
        var prefix = ctx + "hotel/service"
        $("#form-service-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-service-add').serialize());
            }
        }

        $("input[name='ctime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });
        function uploadFile() {
            var formData = new FormData();
            if ($('#filePath')[0].files[0] == null) {
                $.modal.alertWarning("请先选择文件路径");
                return false;
            }
            formData.append('file', $('#filePath')[0].files[0]);
            $.ajax({
                url: "/common/upload/image",
                type: 'post',
                cache: false,
                data: formData,
                processData: false,
                contentType: false,
                dataType: "json",
                success: function(result) {
                    if(result.code == 0)
                    {
                        $("#pic").val(result.fileName);
                        $("#uploadImg").attr("src", result.fileName);
                    }
                    else{
                        $.modal.alertError(result.msg);
                    }
                }
            });
        }
    </script>
</body>
</html>